﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bird : MonoBehaviour {

    public float timer = 0;
    public int frameNumber = 10;
    public int frameCount = 0;

    public bool animations = false;
    public bool canJump = false;



	// Use this for initialization
	void Start () {
        //Rigidbody rigidbody = GetComponent<Rigidbody>();

        //rigidbody.velocity = new Vector3(4, 0, 0);
	}
	
	// Update is called once per frame
	void Update () {
        if (GameManager.instance.GameState==GameManager.GAMRSTATE_PLAYING)
        {
            timer += Time.deltaTime;
            if (timer >= 1.0f / frameNumber)
            {
                frameCount++;
                timer -= 1.0f / frameNumber;
                int frameIndex = frameCount % 3;
                gameObject.GetComponent<MeshRenderer>().material.SetTextureOffset("_MainTex", new Vector2(0.33333f * frameIndex, 0));

            }
        }

        if (GameManager.instance.GameState==GameManager.GAMRSTATE_PLAYING)
        {
            if (Input.GetMouseButton(0))
            {
                Rigidbody rigidbody = GetComponent<Rigidbody>();
                Vector3 vol = rigidbody.velocity;
                rigidbody.velocity = new Vector3(vol.x, 5, vol.z);
            }
        }

        
	}
    public void GetLife()
    {
        GetComponent<Rigidbody>().useGravity = true;
        Rigidbody rigidbody = GetComponent<Rigidbody>();
        rigidbody.velocity = new Vector3(4, 0, 0);
    }
}
